﻿/**************************************************************************
创建时间:	2020/5/14
作	  者:	张存
邮 	  箱:	zhangcunliang@126.com

Copyright (c) zhcun.cn

描	述：
记	录：
***************************************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZhCun.DBModel;
using ZhCun.Utils;
using ZhCun.Utils.Helpers;
using ZhCun.Win.Extend;
using ZhCun.Win.ExtendSearch;

namespace ZhCun.Win.ExtendGridView
{
    public partial class FrmGridColumn : FrmCrud
    {
        public FrmGridColumn()
        {
            InitializeComponent();
        }

        readonly GridViewBLL BLLObj = new GridViewBLL();

        #region CRUD 重写

        /// <summary>
        /// 创建新增窗体的方法
        /// </summary>
        protected override FrmBaseEdit CreateAddForm()
        {
            var frm = new FrmGridColumnEdit();
            frm.OwnerForm = Owner;
            frm.SearchFormName = BLLObj.SearchForm;
            frm.DgvRowCount = dgv.RowCount;
            return frm;
        }
        /// <summary>
        /// 获取数据源的方法 （必须重写）
        /// </summary>
        protected override DataTable GetDataSource(int pageNo, int pageSize, string searchVal, out int rowCount)
        {
            return BLLObj.GetData(pageNo, pageSize, searchVal, out rowCount);
        }
        /// <summary>
        /// 新增处理
        /// </summary>
        protected override ApiResult<string> AddSaveHandle(object m)
        {
            return BLLObj.Add(m as Sys_GridColumn);
        }
        /// <summary>
        /// 更新处理
        /// </summary>
        protected override ApiResult<string> EditSaveHandle(object m)
        {
            return BLLObj.Edit(m as Sys_GridColumn);
        }

        public override object GetGridSelected()
        {
            return dgv.GetSelectedClassData<Sys_GridColumn>();
        }

        /// <summary>
        /// 删除处理
        /// </summary>
        protected override ApiResult DelHandle(object m)
        {
            return BLLObj.Del(m as Sys_GridColumn);
        }
        /// <summary>
        /// 创建保存实体对象
        /// </summary>
        public override object CreateSaveModel()
        {
            return new Sys_GridColumn();
        }

        protected override void AdSearch_Click(object sender, EventArgs e)
        {
            ADSearch(BLLObj.ADJoinSql, BindDataSource);
        }


        #endregion

        private void FrmGridColumn_Load(object sender, EventArgs e)
        {
            if (Owner is IFormContainer dgvContainer)
            {
                BLLObj.SearchForm = dgvContainer.ContainerName;

                if (IsManager)
                {
                    toolStripTop.LoopItem(SetRights);

                    void SetRights(ToolStripItem item)
                    {
                        if (!item.Enabled) item.Enabled = item.Visible = true;
                    }
                }
                BtnSearch_Click(sender, e);
            }
        }
    }
}
